package com.ganbo.pattern.singleton;

/**
 * 静态内部类方式单利模式
 *
 * @Author: ganbo
 * @Date: 2020/6/8 20:55
 */
public class StaticInnerClassSingleton {

    private static class SingletonHolder {
        private static StaticInnerClassSingleton instance = new StaticInnerClassSingleton();
    }

    private StaticInnerClassSingleton() {
        //防止通过反射破解该单利模式
        if(SingletonHolder.instance!=null){
            throw new RuntimeException("不允许重复实例化");
        }
    }

    public StaticInnerClassSingleton getInstance() {
        return SingletonHolder.instance;
    }
}
